home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / Python-1.4 / Docs / Regular_Expressions_2.txt < prev    next >
Text File  |  1998-06-24  |  2KB  |  60 lines

  1. Newsgroups: comp.lang.python
  2. From: Dave Mitchell <davem@magnet.com>
  3. Subject: Re: Regular expressions, pattern matching
  4. Date: Mon, 27 Nov 1995 15:20:51 GMT
  5.  
  6. > The Python library documentation says that pattern matching is done like 
  7. > Emacs, and as far as I can see, gives no further explanation. I don't have the 
  8. > faintest idea how Emacs pattern matching works, or how the various pattern 
  9. > matching modules/functions interact, so can someone point me to something like 
  10. > the extensive Perl documentation.
  11.  
  12. This is copied w/o permission from O'Reilly's perl book, p. 25
  13.  
  14.     .    matches any character except newline
  15.  [a-z0-9]    matches any single character of set
  16.  [^a-z0-9]    matches any single character NOT in set
  17.        \d    matches a digit, same as [0-9]
  18.        \D    matches a non-digit, same as [^0-9]
  19.        \w    matches an alphanumeric (word) character [a-zA-Z0-9_]
  20.        \W    matches a non-word character [^a-zA-Z0-9_]
  21.        \s    matches a whitespace char (space, tab, newline...)
  22.        \S    matches a non-whitespace char
  23.        \n    matches a newline
  24.        \r    matches a return
  25.        \t    matches a tab
  26.        \f    matches a formfeed
  27.        \b     matches a backspace (inside [] only)
  28.        \0    matches a null char
  29.      \000    also matches a null char because...
  30.      \nnn    matches an ASCII char of that octal value
  31.      \xnn    matches an ASCII char of that hex value
  32.      \cX    matches an ASCII control char
  33.  \metachar    matches the char itself (\|,\.,\*...)
  34.     (abc)    remembers the match for later backreferences
  35.       \1    matches the first set of parens matched
  36.       \2        matches whatever the second set of parens matched
  37.       \3    and so on...
  38.  
  39.       x?    matches 0 or 1 x's, where x is any of the above
  40.       x*    matches 0 or more x's
  41.       x+    matches 1 or more x's
  42.    x{m,n}    matches at least m x's but no more than n
  43.  
  44.    a,b,c    matches all of a, b, and c in order
  45. fee|fie|foe    matches one of fee, fie, or foe
  46.  
  47.       \b    matches a word boundary (outside [] only)
  48.       \B     matches a non-word boundary
  49.        ^    anchors match to the beginning of a line or string
  50.        $    anchors match to the end of a line or string
  51.  
  52.  
  53.  
  54.  
  55.                                 Dave
  56.  
  57.  
  58.